#include "GCTools.h"
#include <windows.h>
#include "Psapi.h"
#pragma   comment(lib, "psapi.lib ")

namespace gcstock
{
    GCTools* GCTools::pInstance = NULL;

    void GCTools::initialize()
    {
        if(!pInstance)
        {
            pInstance = new GCTools;
            
        }
    }

    void GCTools::release()
    {
        if(pInstance)
        {
            delete pInstance;
            pInstance = NULL;
        }
    }

    void GCTools::printCPUUsage()
    {

    }

    void GCTools::printMemUsage(const GCCHAR* file, const GCINT line)
    {
#ifdef WIN32
        HANDLE hProcess;
        PROCESS_MEMORY_COUNTERS pmc;
        
        DWORD processID;
        hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
                                PROCESS_VM_READ,
                                FALSE, 
                                processID );
        if (NULL == hProcess)
            return;
        
        if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
        {
            printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
            printf( "\tPeakWorkingSetSize: 0x%08X\n",  
                pmc.PeakWorkingSetSize );
            printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
            printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n",  
                pmc.QuotaPeakPagedPoolUsage );
            printf( "\tQuotaPagedPoolUsage: 0x%08X\n",  
                pmc.QuotaPagedPoolUsage );
            printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n",  
                pmc.QuotaPeakNonPagedPoolUsage );
            printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n",  
                pmc.QuotaNonPagedPoolUsage );
            printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );  
            printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );
        }
    }
#endif // WIN32
}